package com.webSite.demo.cy.test;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ImageUtil;
import cn.hutool.core.util.NumberUtil;

public class FileCut {

	private static final int x = 0;
	private static final int y = 0;
	private static final int DefaultWidth = 700;
	private static final int DefaultHeight = 1000;
	
	public static void main(String[] args) {
		// 封装目录
		File srcFolder = new File("C:\\Users\\yanfa00027\\Desktop\\2\\1.jpg");
		ImageCut(srcFolder);
	}

	private static void ImageCut(File srcFolder) {
		BufferedImage sourceImg = null;
		try {
			sourceImg = ImageIO.read(new FileInputStream(srcFolder));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("文件获取失败");
		}
		String newFiler = srcFolder.getAbsolutePath().replace(".jpg", "");
		//创建文件夹
		FileUtil.mkdir(newFiler);
		//总共可以截取几次
		double sum = NumberUtil.div((float)sourceImg.getHeight(), (float)DefaultHeight);
		for(int i=0;i<=sum;i++) {
			ImageUtil.cut(srcFolder, new File(newFiler+"\\"+i+".jpg"), new Rectangle(0,i*DefaultHeight,sourceImg.getWidth(),DefaultHeight));
		}
	}
}
